package com.project.server.service.operate.impl;

import com.project.common.core.domain.BaseServer;
import com.project.server.domain.operate.TOperateInvestment;
import com.project.server.mapper.operate.TOperateInvestmentMapper;
import com.project.server.service.operate.ITOperateInvestmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.project.server.utils.DelTagUtil.getTextFromHtml;

/**
 * 运营管理招商引资Service业务层处理
 *
 * @author project
 * @date 2021-07-01
 */
@Service
public class TOperateInvestmentServiceImpl extends BaseServer implements ITOperateInvestmentService {

    private static final Logger log = LoggerFactory.getLogger(TOperateInvestmentServiceImpl.class);

    @Resource
    private TOperateInvestmentMapper tOperateInvestmentMapper;

    /**
     * 查询运营管理招商引资
     *
     * @param investmentId 运营管理招商引资ID
     * @return 运营管理招商引资
     */
    @Override
    public TOperateInvestment selectTOperateInvestmentById(Long investmentId) {
        TOperateInvestment tOperateInvestment = tOperateInvestmentMapper.selectTOperateInvestmentById(investmentId);
        TOperateInvestment obj = new TOperateInvestment();
        //增加点击次数
        obj.setInvestmentId(investmentId);
        Long contentHit = tOperateInvestment.getContentHit();
        contentHit++;
        obj.setContentHit(contentHit);
        tOperateInvestmentMapper.updateTOperateInvestment(obj);
        return tOperateInvestment;
    }

    /**
     * 查询运营管理招商引资列表
     *
     * @param tOperateInvestment 运营管理招商引资
     * @return 运营管理招商引资
     */
    @Override
    public List<TOperateInvestment> selectTOperateInvestmentList(TOperateInvestment tOperateInvestment) {
        return tOperateInvestmentMapper.selectTOperateInvestmentList(tOperateInvestment);
    }

    /**
     * 处理导出内容中的html标签
     */
    @Override
    public List<TOperateInvestment> selectTOperateInvestmentDelTags(TOperateInvestment tOperateInvestment){
        List<TOperateInvestment> operateInvestments = tOperateInvestmentMapper.selectTOperateInvestmentList(tOperateInvestment);
        for(int i = 0;i<operateInvestments.size();i++){
            TOperateInvestment tOperateInvestment1 = operateInvestments.get(i);
            tOperateInvestment1.setInvestmentDetails(getTextFromHtml(tOperateInvestment1.getInvestmentDetails()));
        }
        return operateInvestments;
    }


    /**
     * 新增运营管理招商引资
     *
     * @param tOperateInvestment 运营管理招商引资
     * @return 结果
     */
    @Override
    public int insertTOperateInvestment(TOperateInvestment tOperateInvestment) {
        super.insert(tOperateInvestment);
        return tOperateInvestmentMapper.insertTOperateInvestment(tOperateInvestment);
    }

    /**
     * 修改运营管理招商引资
     *
     * @param tOperateInvestment 运营管理招商引资
     * @return 结果
     */
    @Override
    public int updateTOperateInvestment(TOperateInvestment tOperateInvestment) {
        super.update(tOperateInvestment);
        return tOperateInvestmentMapper.updateTOperateInvestment(tOperateInvestment);
    }

    /**
     * 批量删除运营管理招商引资
     *
     * @param investmentIds 需要删除的运营管理招商引资ID
     * @return 结果
     */
    @Override
    public int deleteTOperateInvestmentByIds(Long[] investmentIds) {
        return tOperateInvestmentMapper.deleteTOperateInvestmentByIds(investmentIds);
    }

    /**
     * 删除运营管理招商引资信息
     *
     * @param investmentId 运营管理招商引资ID
     * @return 结果
     */
    @Override
    public int deleteTOperateInvestmentById(Long investmentId) {
        return tOperateInvestmentMapper.deleteTOperateInvestmentById(investmentId);
    }
}
